//
//  RBGSelectorValue.m
//  BateauGenerique
//
//  Created by Florent Champigny on 03/06/2014.
//  Copyright (c) 2014 Kevin De Jesus Ferreira. All rights reserved.
//

#import "RBGSelectorValue.h"
#import "RBGAppDelegate.h"
#import "UIImageView+WebCache.h"
#import "RBGNavigationBar.h"

@interface RBGSelectorValue ()<UITableViewDelegate,UITableViewDataSource>
{
    RBGAppDelegate *appDelegate;
}

@end


@implementation RBGSelectorValue



- (void)viewDidLoad
{
    [super viewDidLoad];
    
    appDelegate = (RBGAppDelegate *)[[UIApplication sharedApplication] delegate];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    [self.fond setImageWithURL:[NSURL URLWithString:appDelegate.donnees.parametres.imageFond]];
    self.tableView.backgroundColor = [UIColor clearColor];
    
    [self setTitle:@"Ma Recherche"];
    
}

-(void) viewWillAppear:(BOOL)animated
{
    [[NSUserDefaults standardUserDefaults] setObject: [NSArray arrayWithObjects:@"fr", nil] forKey:@"AppleLanguages"]; // On met à jour la langue choisie fr -> pour la langue française
    [[NSUserDefaults standardUserDefaults] synchronize];
    
    if(self.facultatif)
        [self.values insertObject:@"Indifférent" atIndex:0];

    [self.tableView reloadData];
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    int index = indexPath.row;
    
    if(self.facultatif)
        --index;
    
    [self.delegate receiveValueSelected:index andTypeValeur:self.type];
    
    // Peut être pas le bon controller
    [self.navigationController popViewControllerAnimated:YES];

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.values count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   
    UITableViewCell * cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"SimpleCell"];
    
    [cell.textLabel setText:[self.values objectAtIndex:indexPath.row]];
    
    [cell.textLabel setTextColor:appDelegate.donnees.parametres.fontColorDeux];
  
    [cell.textLabel setFont: [UIFont fontWithName:@"Arial" size:13.0f]];

    UIView *selectedView = [[UIView alloc]init];
    selectedView.backgroundColor = appDelegate.donnees.parametres.backgroundColorDeux;
    cell.selectedBackgroundView =  selectedView;

    [cell setBackgroundColor:[UIColor clearColor]];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    

    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 40;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 100 * 2;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView * view = [[UIView alloc]init];
    [view setBackgroundColor:[UIColor clearColor]];
    return view;
}
@end
